package com.jwcao.common.cast.operation.access.field;

import com.jwcao.common.cast.annotation.CastField;
import com.jwcao.common.cast.operation.CastFlow;
import com.jwcao.common.scan.object.ScanField;

/**
 * name: RecursionAccessOperation description: TODO
 *
 * @author caojingwei date: 2023/3/23 18:47
 */
public class RecursionAccessOperation extends CastFieldAccessOperation {

    private final CastFlow castFlow;

    public RecursionAccessOperation(CastField castField,
        ScanField sourceField, ScanField targetField,
        CastFlow castFlow) {
        super(castField, sourceField, targetField);
        this.castFlow = castFlow;
    }

    @Override
    public Object execute(Object object) {
        Object value = super.execute(object);
        if (value != null) {
            return castFlow.execute(value);
        }
        return null;
    }
}
